<?php
class LevelController extends Controller {
    //private $manage = null;
    public function __construct() {
        parent::__construct();
        $this->viewFolder = 'level/';
        //$this->manage = new ManageModel();
    }
    //等级列表
    public function index() {
        parent::page(3);
        $this->tpl->assign('allLevel',$this->model->findAll());
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'level_list.tpl');
    }
    public function add() {
        $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'pop_add_level.tpl');
    }
    public function addSubmit() {
        if(isset($_POST['add'])){
            echo $this->model->add() ? 'success' : 'failed';
        }
    }
    //ajax方式判断
    public function isOneByAjax() {
        if(!empty($_GET)){
            echo $this->model->isOneByAjax() ? 'false' : 'true';
        }
    }
    /*
     * 删除管理员等级
     */
    public function del() {
        if(isset($_GET['id'])){
            echo $this->model->del() ? 'success' : 'failed';
        }
    }
    //修改
    public function update() {
        if(isset($_GET['id'])){
            $this->tpl->assign('oneLevel',$this->model->findOne());
            $this->tpl->display(SMARTY_ADMIN.$this->viewFolder.'pop_update_level.tpl');
        }
    }
    public function updateSubmit() {
        if(isset($_GET['id'])){
            if($this->model->update() !== false){
                echo 'success';
            }
        }
    }
}